package com.uk.data.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.uk.data.ejbs.AuditLog;

@Entity()
@Table(name="KONTRATA")
@EntityListeners(value=AuditLog.class)
public class Kontrata implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -947847458651507546L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	private String emri;
	private String mbiemri;
	private String adresa;

	@Transient
	private String nipt;
	
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="DATA_REGJISTRIMIT")
	private Date dataRegjistrimit;
	
	@ManyToOne
	private BashkiKomuna bashkiKomuna;
	
	@ManyToOne
	private Perdorimi perdorimi;
	
	@OneToMany(mappedBy="kontrata")
	private List<Fatura> faturat;


	@Transient
	private int faturaPapaguarNeTotal;
	

	public int getFaturaPapaguarNeTotal(){
		
		return faturaPapaguarNeTotal;
	}
	
	public void setFaturaPapaguarNeTotal(int faturaPapaguarNeTotal) {
		this.faturaPapaguarNeTotal = faturaPapaguarNeTotal;
	}
	
	public Kontrata() {
		super();
		
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getEmri() {
		return emri;
	}
	public void setEmri(String emri) {
		this.emri = emri;
	}
	public String getMbiemri() {
		return mbiemri;
	}
	public void setMbiemri(String mbiemri) {
		this.mbiemri = mbiemri;
	}
	public String getAdresa() {
		return adresa;
	}
	public void setAdresa(String adresa) {
		this.adresa = adresa;
	}
	
	
	public Date getDataRegjistrimit() {
		return dataRegjistrimit;
	}
	public void setDataRegjistrimit(Date dataRegjistrimit) {
		this.dataRegjistrimit = dataRegjistrimit;
	}
	
	public BashkiKomuna getBashkiKomuna() {
		return bashkiKomuna;
	}
	public void setBashkiKomuna(BashkiKomuna bashkiKomuna) {
		this.bashkiKomuna = bashkiKomuna;
	}
	public Perdorimi getPerdorimi() {
		return perdorimi;
	}
	public void setPerdorimi(Perdorimi perdorimi) {
		this.perdorimi = perdorimi;
	}
	public String getNipt() {
		return nipt;
	}
	public void setNipt(String nipt) {
		this.nipt = nipt;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((adresa == null) ? 0 : adresa.hashCode());
		result = prime * result
				+ ((bashkiKomuna == null) ? 0 : bashkiKomuna.hashCode());
		result = prime
				* result
				+ ((dataRegjistrimit == null) ? 0 : dataRegjistrimit.hashCode());
		result = prime * result + ((emri == null) ? 0 : emri.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((mbiemri == null) ? 0 : mbiemri.hashCode());
		result = prime * result + ((nipt == null) ? 0 : nipt.hashCode());
		result = prime * result
				+ ((perdorimi == null) ? 0 : perdorimi.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Kontrata other = (Kontrata) obj;
		if (adresa == null) {
			if (other.adresa != null)
				return false;
		} else if (!adresa.equals(other.adresa))
			return false;
		if (bashkiKomuna == null) {
			if (other.bashkiKomuna != null)
				return false;
		} else if (!bashkiKomuna.equals(other.bashkiKomuna))
			return false;
		if (dataRegjistrimit == null) {
			if (other.dataRegjistrimit != null)
				return false;
		} else if (!dataRegjistrimit.equals(other.dataRegjistrimit))
			return false;
		if (emri == null) {
			if (other.emri != null)
				return false;
		} else if (!emri.equals(other.emri))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (mbiemri == null) {
			if (other.mbiemri != null)
				return false;
		} else if (!mbiemri.equals(other.mbiemri))
			return false;
		if (nipt == null) {
			if (other.nipt != null)
				return false;
		} else if (!nipt.equals(other.nipt))
			return false;
		if (perdorimi == null) {
			if (other.perdorimi != null)
				return false;
		} else if (!perdorimi.equals(other.perdorimi))
			return false;
		return true;
	}
	public List<Fatura> getFaturat() {
		return faturat;
	}
	public void setFaturat(List<Fatura> faturat) {
		this.faturat = faturat;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Kontrata [id=");
		builder.append(id);
		builder.append(", emri=");
		builder.append(emri);
		builder.append(", mbiemri=");
		builder.append(mbiemri);
		builder.append(", adresa=");
		builder.append(adresa);
		builder.append(", nipt=");
		builder.append(nipt);
		builder.append(", dataRegjistrimit=");
		builder.append(dataRegjistrimit);
		builder.append(", bashkiKomuna=");
		builder.append((bashkiKomuna !=null)?bashkiKomuna.getId():"");
		builder.append(", perdorimi=");
		builder.append((perdorimi!= null)?perdorimi.getId():"");
		builder.append(", faturat=");
		builder.append(faturat);
		builder.append(", faturaPapaguarNeTotal=");
		builder.append(faturaPapaguarNeTotal);
		builder.append("]");
		return builder.toString();
	}
	
	
	



	

	
	
	
	
	
}
